package com.candy.service.impl;

import com.candy.bean.UserInfo;
import com.candy.dao.UserInfoMapper;
import com.candy.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UserInfoServiceImpl implements UserInfoService {
    @Autowired
    UserInfoMapper userInfoMapper;

    /**
     * 根据条件查询用户信息
     * @param userInfo
     * @return
     */
    @Override
    public List<UserInfo> getUserInfoes(UserInfo userInfo) {
        return userInfoMapper.getUserInfoes(userInfo);
    }

    /**
     * 新增、编辑方法
     * @param userInfo
     * @return 若新增成功返回true，反之返回false
     */
    @Override
    public boolean editUserInfo(UserInfo userInfo) {
        int num=0;
//        获取用户传递的id值
        Integer userId=userInfo.getId();
//        若id值为空则执行新增方法，或id不为空则执行编辑方法
        if(userId!=null){
            num=userInfoMapper.updateByPrimaryKeySelective(userInfo);
        }else {
            num=userInfoMapper.insertSelective(userInfo);
        }
       if (num>0){
           return true;
       }else {
           return false;
       }
    }
}
